home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / xsharp21.zip / MODE.ASM < prev    next >
Assembly Source File  |  1992-03-27  |  4KB  |  89 lines

  1. ; Mode X (320x240, 256 colors) mode set routine. Works on all VGAs.
  2. ; ****************************************************************
  3. ; * Revised 6/19/91 to select correct clock; fixes vertical roll *
  4. ; * problems on fixed-frequency (IBM 851X-type) monitors.        *
  5. ; ****************************************************************
  6. ; C near-callable as:
  7. ;       void Set320x240Mode(void);
  8. ; Tested with TASM 2.0.
  9. ; Modified from public-domain mode set code by John Bridges.
  10.  
  11. SC_INDEX equ    03c4h   ;Sequence Controller Index
  12. CRTC_INDEX equ  03d4h   ;CRT Controller Index
  13. MISC_OUTPUT equ 03c2h   ;Miscellaneous Output register
  14. SCREEN_SEG equ  0a000h  ;segment of display memory in mode X
  15.  
  16.         .model  small
  17.         .data
  18. ; Index/data pairs for CRT Controller registers that differ between
  19. ; mode 13h and mode X.
  20. CRTParms label  word
  21.         dw      00d06h  ;vertical total
  22.         dw      03e07h  ;overflow (bit 8 of vertical counts)
  23.         dw      04109h  ;cell height (2 to double-scan)
  24.         dw      0ea10h  ;v sync start
  25.         dw      0ac11h  ;v sync end and protect cr0-cr7
  26.         dw      0df12h  ;vertical displayed
  27.         dw      00014h  ;turn off dword mode
  28.         dw      0e715h  ;v blank start
  29.         dw      00616h  ;v blank end
  30.         dw      0e317h  ;turn on byte mode
  31. CRT_PARM_LENGTH equ     (($-CRTParms)/2)
  32.  
  33.         .code
  34.         public  _SetGraphicsMode
  35. _SetGraphicsMode proc    near
  36.         push    bp      ;preserve caller's stack frame
  37.         push    si      ;preserve C register vars
  38.         push    di      ; (don't count on BIOS preserving anything)
  39.  
  40.         mov     ax,13h  ;let the BIOS set standard 256-color
  41.         int     10h     ; mode (320x200 linear)
  42.  
  43.         mov     dx,SC_INDEX
  44.         mov     ax,0604h
  45.         out     dx,ax   ;disable chain4 mode
  46.         mov     ax,0100h
  47.         out     dx,ax   ;synchronous reset while setting Misc Output
  48.                         ; for safety, even though clock unchanged
  49.         mov     dx,MISC_OUTPUT
  50.         mov     al,0e3h
  51.         out     dx,al   ;select 25 MHz dot clock & 60 Hz scanning rate
  52.  
  53.         mov     dx,SC_INDEX
  54.         mov     ax,0300h
  55.         out     dx,ax   ;undo reset (restart sequencer)
  56.  
  57.         mov     dx,CRTC_INDEX ;reprogram the CRT Controller
  58.         mov     al,11h  ;VSync End reg contains register write
  59.         out     dx,al   ; protect bit
  60.         inc     dx      ;CRT Controller Data register
  61.         in      al,dx   ;get current VSync End register setting
  62.         and     al,7fh  ;remove write protect on various
  63.         out     dx,al   ; CRTC registers
  64.         dec     dx      ;CRT Controller Index
  65.         cld
  66.         mov     si,offset CRTParms ;point to CRT parameter table
  67.         mov     cx,CRT_PARM_LENGTH ;# of table entries
  68. SetCRTParmsLoop:
  69.         lodsw           ;get the next CRT Index/Data pair
  70.         out     dx,ax   ;set the next CRT Index/Data pair
  71.         loop    SetCRTParmsLoop
  72.  
  73.         mov     dx,SC_INDEX
  74.         mov     ax,0f02h
  75.         out     dx,ax   ;enable writes to all four planes
  76.         mov     ax,SCREEN_SEG ;now clear all display memory, 8 pixels
  77.         mov     es,ax         ; at a time
  78.         sub     di,di   ;point ES:DI to display memory
  79.         sub     ax,ax   ;clear to zero-value pixels
  80.         mov     cx,8000h ;# of words in display memory
  81.         rep     stosw   ;clear all of display memory
  82.  
  83.         pop     di      ;restore C register vars
  84.         pop     si
  85.         pop     bp      ;restore caller's stack frame
  86.         ret
  87. _SetGraphicsMode endp
  88.         end
  89.